###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# Cool.pm.pl -> Cool module                                                   #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Cool;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
require "Error.pm.pl";
require "Standard.pm.pl";

use POSIX;
use strict;

require "Output/Cool.pm.pl";

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless($self, $class);
}

sub DESTROY { }

###############################################################################
# show subroutine
sub show {
  my $self = shift;
  my %in = ("DB" => undef, "STATIC" => 0, @_);

  #----------------------------------------------------------------------#
  # Getting data...                                                      #

  &Standard::ShowStatic(DB => $in{'DB'}, TYPE => "Cool") unless ($in{'STATIC'});

  my ($Resources, $ResourcesIndex) = $in{'DB'}->Query (
    TABLE   => "Resources",
    WHERE   => {
      STATUS  => ["1"],
      RATING  => [">".($GENERAL->{'WHAT_COOL_CUTOFF'} - 1)]
    },
    MATCH   => "ALL",
    SORT    => $GENERAL->{'WHAT_COOL_SORT_FIELD'},
    BY      => $GENERAL->{'WHAT_COOL_SORT_BY'},
    TO      => "0-".($GENERAL->{'WHAT_COOL_NUMBER'} - 1)
  );
  
  my @Categories = &Standard::MapArray("\${CATEGORY}", $Resources);

  my ($Categories, $CategoriesIndex);
  if (scalar(@Categories) >= 1) {
    ($Categories, $CategoriesIndex) = $in{'DB'}->Query(
      TABLE   => "Categories",
      WHERE   => {
        ID  => \@Categories
      },
      MATCH   => "ANY"
    );
  }

  my %INPUT;
  
  $INPUT{'RESOURCES'}     = $Resources;
  $INPUT{'CATEGORIES'}    = $Categories;
  $INPUT{'CATEGORIES_IX'} = $CategoriesIndex;
  
  $INPUT{'TOTAL_RESOURCES'} = $in{'DB'}->Query(
    TABLE   => "Resources",
    WHERE   => {
      STATUS  => ["1"],
      RATING  => [">".($GENERAL->{'WHAT_COOL_CUTOFF'} - 1)]
    },
    MATCH   => "ALL",
    COUNT   => 1
  );

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Skin = Skin::Cool->new();

  return $Skin->show(input => \%INPUT, static => 1) if ($in{'STATIC'});

  &Standard::PrintHTMLHeader();
  print $Skin->show(input => \%INPUT);

  return 1;
}

1;